package edu.szu.huhanpeng.doodlingFight.view.components 
{
	import com.bit101.components.Label;
	import com.bit101.components.Style;
	import com.bit101.components.Window;
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.text.TextFormat;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class PlayerWindow extends Window 
	{
		//private static const _NAME_WIDTH:int = 90;
		//private static const _NAME_HEIGHT:int = 25;
		//private static const _NAME_X:int = (GlobalConst.setting.PLAYER_WINDOW_WIDTH - _NAME_WIDTH) / 2;
		private static const _NAME_Y:int = 120;		
		
		//private static const _SCORE_WIDTH:int = 120;
		//private static const _SCORE_HEIGHT:int = 80;
		//private static const _SCORE_X:int = (GlobalConst.setting.PLAYER_WINDOW_WIDTH - _SCORE_WIDTH) / 2;
		private static const _SCORE_Y:int = 200;
		
		protected var _nameLabel:Label;
		protected var _scoreLabel:Label;
		/////////////////////////////////////////////////////////////////////
		//getter setter                                                    //
		/////////////////////////////////////////////////////////////////////
		
		
       		
		
		/////////////////////////////////////////////////////////////////////
		//构造函数                                                         //
		/////////////////////////////////////////////////////////////////////
		public function PlayerWindow(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0, title:String="Window") 
		{
			super( parent, xpos, ypos, title);
		}
		
		override protected function init():void 
		{
			super.init();
			
			initNameLabel();
			initScoreLabel();
		}
		
		protected function initScoreLabel():void 
		{
			_scoreLabel = new Label( content, 0, _SCORE_Y ,"0000");
			_scoreLabel.format = new TextFormat( null, Style.fontSize * 2 ); 
			_scoreLabel.addEventListener( Event.RESIZE, onResize );
		}
		

		
		protected function initNameLabel():void 
		{
			_nameLabel = new Label( content, 0, _NAME_Y,"未设置姓名" );
			_nameLabel.addEventListener( Event.RESIZE, onResize );
		}		
		
		
		
		/////////////////////////////////////////////////////////////////////
		//接口                                                             //
		/////////////////////////////////////////////////////////////////////
		public function setPlayerName(str:String):void
		{
			_nameLabel.text = str;
		}
		
		public function setScore(score:int):void
		{
			_scoreLabel.text = score.toString();
		}
		
		/////////////////////////////////////////////////////////////////////
		//内部                                                             //
		/////////////////////////////////////////////////////////////////////
		
		private function onResize(e:Event):void 
		{
			var label:Label = e.currentTarget as Label;
			label.move( (GlobalConst.setting.PLAYER_WINDOW_WIDTH - label.width) / 2 , label.y );
		}
	}

}